<?php
    $this->headTitle($this->site_name.' - Admin Message');
?>

<script type="text/javascript" src="/js/ui/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.mouse.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.draggable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.droppable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.sortable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.datepicker.min.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>

<style>
	.draggable1, .draggable2 { cursor:pointer;}
	.sortable { list-style-type: none; margin: 0; padding: 0;  }
	.sortable li { margin: 0 3px 3px 3px;  }
	.sortable li a { position: absolute;  }
	div .left-column { width: 47%; font-size:12px;float:left;}
	div .right-column { width: 47%; font-size:12px;float:left;}
	.desc {margin-top:10px;}
	
</style>

<script>
<?php echo "var page_uri='".$_SERVER['REQUEST_URI']."';\n";?>

	function addNews(){
		$("span.ui-dialog-title").text('Add Message');  		
		$("#submit").val('Add Message');
		$("#news-dialog").dialog("open");
	}		

	function updateNews(id){
		
	    $.post("/default/do/get-message", {id: ""+id+""}, function(data)
	   	{
            if(data['news_id']>0) {
    	    	$("#news_content").val(data['news_content']);
    	    	$("#max_display_times").val(data['max_display_times']);
    	    	$("#from_date").val(data['from_date']);
    	    	$("#end_date").val(data['end_date']);
    	    	$('input[name="icon"]:radio').filter("[value="+data['icon']+"]").attr('checked', true); 
    	    	$("#dpt_id").val(data['dpt_id']);
    	    	$("#news_id").val(data['news_id']);

    	    	if (data['important']>0)
    	    		$("#important").attr('checked', true);
    	    	else
    	    		$("#important").attr('checked', false);
    	    	

            	//alert(content);
        		$("span.ui-dialog-title").text('Update Message');  		
        		$("#submit").val('Update Message');
        		$("#news-dialog").dialog("open");
            }else{
    	        alert("Sorry, failed to fetch user information.");
    		}
	    }, "json");
		
	}		
</script>

<script type="text/javascript">   
	$(document).ready(function(){
	    $("#messageForm").validate({
	      rules: {
        	content: {
	          required: true
			}
	      },
	      messages: {
	    	content: {
	          required: "Content can not be empty"
		    }
	      }
	    });

		$("#news-dialog").dialog({autoOpen:false,modal:true,width:800});
		$( "#sortable1" ).sortable();
		$( "#sortable1" ).disableSelection();
		
		$( ".draggable2" ).draggable({revert: true});		  

	    $(".datepicker").datepicker({
			dateFormat: 'yy-mm-dd',
			changeYear: true,
			changeMonth: true,
			showButtonPanel: true,
			autoSize: true        		
		});
		
	  });


	function delNews(id){
		location=page_uri+'?act=del&id='+id;
	}

	function checkImportant(){
		if ($("#important").attr('checked')==true)
			$('input[name="important"]').val(1);
		else
			$('input[name="important"]').val(0);
	}
</script>  

<?php if (!empty($this->success_msg)):?>
<div class="response-msg success ui-corner-all"><?php echo $this->success_msg;?></div>
<?php endif ?>

<?php if (!empty($this->error_msg)):?>
<div class="response-msg error ui-corner-all"><?php echo $this->error_msg;?></div>
<?php endif ?>


<div id="admin-dashboard">

<h2>Admin Message Management</h2>
<div>Messages are displaying on the top bar in each service site.</div> 
<div >
<h3>Messages: <a href="#" class="grey-btn" style="margin-left:180px;display:inline;" onclick="addNews();"><span class="ui-title">Add Message</span></a></h3>

<div class="" id="droppable1">		

	<ul id="sortable1">
<?php if (count($this->all_news)>0):?>
	<?php
	$i=$this->start;
	foreach($this->all_news as $index => $item ){
		$i++;
		//echo '<li id="'.$item['news_id'].'" title="Click to edit" style="padding:0;"><div class=left-column onclick="updateUser(\''.$item['news_id'].'\');" style="cursor:pointer;"><b>'.$i.')&nbsp;&nbsp;'.$item['content'].'</b></div><div class=right-column onclick="updateUser(\''.$item['news_id'].'\');" style="cursor:pointer;"><b>'.$item['create_time'].'</b></div></li>';
		echo '<li id="'.$item['news_id'].'" title="Click to edit" style="padding:0;"><div class="left" style="cursor:pointer;">'.$i.')&nbsp;&nbsp;Create Time: '.$item['create_time'].'</div> <div class="left" style="margin-left:20px"><a class=btn onclick="updateNews(\''.$item['news_id'].'\');">Update</a></div><div class="left" style="margin-left:20px"><a class=btn onclick="if (confirm(\'Are you sure to delete this news?\')) { delNews(\''.$item['news_id'].'\');}">Delete</a></div><div class="clearfix"></div><div style="margin:5px 20px;"><b>'.stripslashes($item['news_content']).'</b></div></li>';
	}
	?>	
<?php else: ?>
	<li>No Message right now.</li>
<?php endif ?>
	</ul>

</div>
 
</div>

<div align=center style="margin:10px 0;"><?php echo $this->paginator; ?></div>


<input type=hidden name=service_id id=service_id value=''>

<div id="news-dialog" title="Add Message" style="display:none;" >
            <?php if (!empty($this->formError)): ?>
            <div class="form_errors_block">
                <?php echo $this->formError; ?>
            </div>
            <?php endif; ?>

            <?php //echo $this->form; ?>
            
			<form class="forms" id="<?php echo $this->form->getName();?>" name=<?php echo $this->form->getName();?> method="post">

								<div>
										<div class="left-column">	
											<label class="desc" for="dpt_id">For Service</label>
											<div><?php echo $this->form->dpt_id;?></div>
										</div>
										
										<div class="right-column">					
											<label class="desc" for="icon">Message Icon</label>
								
											<div>
    <input type=radio id="icon" name="icon" value="0" checked>No Icon&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="1" ><img src="/images/yesup_bar/20x20_icon_1.png">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="2" ><img src="/images/yesup_bar/20x20_icon_2.png">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="3" ><img src="/images/yesup_bar/20x20_icon_3.png">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="4" ><img src="/images/yesup_bar/20x20_icon_4.png">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="5" ><img src="/images/yesup_bar/20x20_icon_5.png">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=radio id="icon" name="icon" value="6" ><img src="/images/yesup_bar/20x20_icon_6.png">&nbsp;&nbsp;&nbsp;&nbsp;
											</div>
										</div>
										<div class=clearfix></div>
																		
										<div class="left-column">	
											<label class="desc" for="from_date">From date</label>
											<div><?php echo $this->form->from_date;?></div>
										</div>
										
										<div class="right-column">					
											<label class="desc" for="end_date">End date</label>
											<div><?php echo $this->form->end_date;?></div>
										</div>
										<div class=clearfix style="height:10px;"></div>

										<div class="left-column">					
											<label class="desc" for="max_display_times">Maximum Display Times</label>
											<div><?php echo $this->form->max_display_times;?></div>
										</div>

										<div class="right-column">					
											<label class="desc" for="end_date">Important Announcement</label>
											<div><?php echo $this->form->important;?></div>
										</div>
																		
										<div class="clearfix"></div>	
										<div>
											<label class="desc" for="news_content">Content</label>								
											<div><?php echo $this->form->news_content;?></div>
										</div>
										<?php echo $this->form->news_id;?>
										<?php echo $this->form->submit;?>
										<!--  input class="btn" type="submit"  id="submit" style="height:30px;font-size:14px;" value="submit"/-->
								</div>
			</form>
            
            
</div>


</div>